from django.db import models
from django.db.models import PROTECT

from apps.users.models import User, RewardScore


class Category(models.Model):
    """分类"""
    name = models.CharField(max_length=20, verbose_name="分类名称")
    parent = models.ForeignKey('self', related_name='subs', null=True, blank=True, on_delete=models.CASCADE,
                               verbose_name='父类别')
    create_time = models.DateTimeField(auto_now_add=True, verbose_name="创建时间")
    update_time = models.DateTimeField(auto_now=True, verbose_name="更新时间")

    class Meta:
        db_table = 'tb_category'
        verbose_name = '分类'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name


class Task(models.Model):
    """悬赏任务"""

    name = models.CharField(max_length=20, verbose_name="任务名称")
    label = models.CharField(max_length=30, verbose_name="任务标签")
    re_score = models.ForeignKey(RewardScore, related_name="rewardscore", verbose_name="悬赏积分")
    is_delete = models.BooleanField(default=False, verbose_name='逻辑删除 ')
    user = models.ForeignKey(User, related_name="user", on_delete=PROTECT, verbose_name='发布用户')
    category = models.ForeignKey(Category, related_name="category", on_delete=PROTECT, verbose_name="所属分类")
    create_time = models.DateTimeField(auto_now_add=True, verbose_name="创建时间")
    update_time = models.DateTimeField(auto_now=True, verbose_name="更新时间")
